<template>
	<view class="page">
		<view class="center">
			<uni-sign-in ref="signIn"></uni-sign-in>
			<view v-if="loginUser.id != null"  class="userInfo">
				<view class="logo-img">
					<image src="../../static/xxx.jpg" mode=""></image>
				</view>
				<view class="logo-title">
					<text class="uer-name">{{loginUser.userName}}</text>
					<text class="uer-name">{{loginUser.phone}}</text>
				</view>
				 
			</view>
			
			<view v-else class="userInfo">
				<view class="logo-img">
					 
				</view>
				 
				<view else  class="logo-title">
					<text @click="goLogin" class="uer-name">登录</text>
				</view>
			
			</view>
			
			<view class="logo-desc">
				<text class="uer-name">{{loginUser.companyName}}</text>
				<text class="uer-name">{{loginUser.duty}}</text>
			</view>

		</view>
		<view class="blank_area">
			<!--占位用-->
		</view>
		<button v-if="loginUser.id !=null" class="logout-btn" @click="loginOut" type="warn">退出登录</button>
		<button v-else class="logout-btn" @click="goLogin" type="warn">跳转登录</button>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from 'vuex';
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
	import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
	// #ifdef APP
	import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	const uniShare = new UniShare()
	// #endif
	const db = uniCloud.database();
	export default {
		// #ifdef APP
		// onBackPress({
		// 	from
		// }) {
		// 	if (from == 'backbutton') {
		// 		this.$nextTick(function() {
		// 			uniShare.hide()
		// 		})
		// 		return uniShare.isShow;
		// 	}
		// },
		// #endif
		data() {
			return {
				gridList: [{
						"text": "1111",
						"icon": "chat"
					},
					{
						"text": "1111",
						"icon": "cloud-upload"
					},
					{
						"text": "1111",
						"icon": "contact"
					},
					{
						"text": "1111",
						"icon": "download"
					}
				],
		 
				listStyles: {
					"height": "150rpx", // 边框高度
					"width": "150rpx", // 边框宽度
					"border": { // 如果为 Boolean 值，可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "100%" // 边框圆角，支持百分比
					}
				},
				loginUser: {id:0}
			}
		},
		onLoad() {
			console.log(313,this.userInfo,this.hasLogin);
			this.loginUser = uni.getStorageSync('userInfo');
			debugger
			if(this.loginUser == ""){
				this.loginUser.id==0
			}
			
			let servicesList = this.servicesList
			//去掉配置中不存在的 注意，在/common/appInit.js中已清除有配置但设备环境不支持的登录项
			// servicesList = servicesList.filter(item => this.loginConfig.includes(item.id))
			// //处理一键登录
			// if (this.loginConfig.includes('univerify')) {
			// 	this.univerifyStyle.privacyTerms.privacyItems = this.agreements
			// 	//设置一键登录功能底下的快捷登录按钮
			// 	servicesList.forEach(({
			// 							  id,
			// 							  logo,
			// 							  path
			// 						  }) => {
			// 		if (id != 'univerify') {
			// 			this.univerifyStyle.buttons.list.push({
			// 				"iconPath": logo,
			// 				"provider": id,
			// 				// path
			// 			})
			// 		}
			// 	})
			// }
			// console.log(servicesList);
			// //如果当前页面为默认登录界面。当前第一优先级的“微信和苹果登录”要隐藏，因为他已经被渲染在默认登录界面顶部
			// if (
			// 		this.getRoute(1) == '/pages/ucenter/login-page/index/index' && ['weixin', 'apple'].includes(this
			// 				.loginConfig[0])
			// ) {
			// 	servicesList = servicesList.filter(item => item.id != this.loginConfig[0])
			// }
			// //去掉当前页面对应的登录选项
			// this.servicesList = servicesList.filter(item => {
			// 	let path = item.path ? item.path.split('?')[0] : '';
			// 	return path != this.getRoute(1)
			// })
			console.log('servicesList', servicesList, this.servicesList);

		},
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
			// #ifdef APP-PLUS
			,
			appVersion() {
				return getApp().appVersion
			}
			// #endif
			,
			appConfig() {
				return getApp().globalData.config
			}
		},
		methods: {
			// ...mapMutations({
			// 	setUserInfo: 'user/login'
			// }),
			toSettings() {
				uni.navigateTo({
					url: "/pages/ucenter/settings/settings"
				})
			},
			signIn() { //普通签到
				this.$refs.signIn.open()
			},
			signInByAd() { //看激励视频广告签到
				this.$refs.signIn.showRewardedVideoAd()
			},
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
			async checkVersion() {
				let res = await callCheckVersion()
				console.log(res);
				if (res.result.code > 0) {
					checkUpdate()
				} else {
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
				}
			},
			toUserInfo() {
				uni.navigateTo({
					url: '/pages/ucenter/userinfo/userinfo'
				})
			},
			tapGrid(index) {
				// uni.showToast({
				// 	// title: '你点击了，第' + (index + 1) + '个',
				// 	title: this.$t('mine.clicked') + " " + (index + 1),
				// 	icon: 'none'
				// });
			},
			loginOut(){
				const that = this
				uni.setStorage({
					key: 'userInfo',
					data: "",
					success: function() {
						that.goLogin()
					}
				});
			},
			goLogin(){
				uni.reLaunch({
					url: "/pages/ucenter/login-page/pwd-login/pwd-login"
				});
			},
			/**
			 * 去应用市场评分
			 */
			gotoMarket() {
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					// 这里填写appstore应用id
					let appstoreid = this.appConfig.marketId.ios; // 'id1417078253';
					plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8');
				}
				if (uni.getSystemInfoSync().platform == "android") {
					var Uri = plus.android.importClass("android.net.Uri");
					var uri = Uri.parse("market://details?id=" + this.appConfig.marketId.android);
					var Intent = plus.android.importClass('android.content.Intent');
					var intent = new Intent(Intent.ACTION_VIEW, uri);
					var main = plus.android.runtimeMainActivity();
					main.startActivity(intent);
				}
				// #endif
			},
			/**
			 * 获取积分信息
			 */
			getScore() {
				if (!this.userInfo) return uni.showToast({
					title: this.$t('mine.checkScore'),
					icon: 'none'
				});
				uni.showLoading({
					mask: true
				})
				db.collection("uni-id-scores")
					.where('"user_id" == $env.uid')
					.field('score,balance')
					.orderBy("create_date", "desc")
					.limit(1)
					.get()
					.then((res) => {
						console.log(res);
						const data = res.result.data[0];
						let msg = '';
						msg = data ? (this.$t('mine.currentScore') + data.balance) : this.$t('mine.noScore');
						uni.showToast({
							title: msg,
							icon: 'none'
						});
					}).finally(() => {
						uni.hideLoading()
					})
			},
			async share() {
				let {
					result
				} = await uniCloud.callFunction({
					name: 'uni-id-cf',
					data: {
						action: 'getUserInviteCode'
					}
				})
				console.log(result);
				let myInviteCode = result.myInviteCode || result.userInfo.my_invite_code
				console.log(myInviteCode);
				let {
					appName,
					logo,
					company,
					slogan
				} = this.appConfig.about
				// #ifdef APP-PLUS
				uniShare.show({
					content: { //公共的分享类型（type）、链接（herf）、标题（title）、summary（描述）、imageUrl（缩略图）
						type: 0,
						href: this.appConfig.h5.url +
							`/#/pages/ucenter/invite/invite?code=uniInvitationCode:${myInviteCode}`,
						title: appName,
						summary: slogan,
						imageUrl: logo +
							'?x-oss-process=image/resize,m_fill,h_100,w_100' //压缩图片解决，在ios端分享图过大导致的图片失效问题
					},
					menus: [{
							"img": "/static/app-plus/sharemenu/wechatfriend.png",
							"text": this.$t('common').wechatFriends,
							"share": {
								"provider": "weixin",
								"scene": "WXSceneSession"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/wechatmoments.png",
							"text": this.$t('common').wechatBbs,
							"share": {
								"provider": "weixin",
								"scene": "WXSceneTimeline"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/weibo.png",
							"text": this.$t('common').weibo,
							"share": {
								"provider": "sinaweibo"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/qq.png",
							"text": "QQ",
							"share": {
								"provider": "qq"
							}
						},
						{
							"img": "/static/app-plus/sharemenu/copyurl.png",
							"text": this.$t('common').copy,
							"share": "copyurl"
						},
						{
							"img": "/static/app-plus/sharemenu/more.png",
							"text": this.$t('common').more,
							"share": "shareSystem"
						}
					],
					cancelText: this.$t('common').cancelShare,
				}, e => { //callback
					console.log(e);
				})
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		background-color: #169BD5;
	}

	/* #endif*/

	.center {
		flex-direction: column;
		background-color: #169BD5;
		padding-bottom: 40rpx;
	}

	.userInfo {
		width: 750rpx;
		padding: 20rpx 20rpx 50rpx 20rpx;
		padding-top: 50px;
		// background-image: url(../../static/uni-center/headers.png);
		flex-direction: row;
		align-items: center;
	}

	.logo-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 150rpx;
		border-radius: 8rpx;
		overflow: hidden;
		margin: 0 50rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.logo-title {
		flex: 1;
		align-items: flex-start;
		justify-content: space-around;
		flex-direction: column;

		.uer-name {
			height: 100rpx;
			line-height: 100rpx;
			font-size: 38rpx;
			color: #FFFFFF;
		}
	}

	.logo-desc {
		display: flex;
		align-items: flex-start;
		justify-content: flex-start;
		flex-direction: row;
		padding: 0 80rpx;

		.uer-name {
			height: 100rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			margin-right: 70rpx;
		}
	}

	.blank_area {
		height: 680rpx;
	}

	.logout-btn {
		width: 75vw;
		margin-bottom: 120rpx;
	}



	.center-list {
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}

	.center-list-cell {
		width: 750rpx;
		background-color: #007AFF;
		height: 40rpx;
	}

	.grid {
		background-color: #FFFFFF;
		margin-bottom: 6px;
	}

	.uni-grid .text {
		font-size: 30rpx;
		height: 25px;
		line-height: 25px;
		color: #817f82;
	}

	.uni-grid .item ::v-deep .uni-grid-item__box {
		justify-content: center;
		align-items: center;
	}


	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
	.center-list ::v-deep .uni-list--border:after {
		-webkit-transform: scaleY(0.2);
		transform: scaleY(0.2);
		margin-left: 80rpx;
	}

	.center-list ::v-deep .uni-list--border-top,
	.center-list ::v-deep .uni-list--border-bottom {
		display: none;
	}

	/* #endif */
	.item-footer {
		flex-direction: row;
		align-items: center;
	}

	.item-footer-text {
		color: #999;
		font-size: 24rpx;
		padding-right: 10rpx;
	}

	.item-footer-badge {
		width: 20rpx;
		height: 20rpx;
		/* #ifndef APP-NVUE */
		border-radius: 50%;
		/* #endif */
		/* #ifdef APP-NVUE */
		border-radius: 10rpx;
		/* #endif */
		background-color: #DD524D;
	}
</style>
